package com.example.alarm.bl;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.example.alarm.AlarmApplication;
import com.example.alarm.Config;
import com.example.alarm.ui.AlarmActivity;
import com.example.alarm.ui.receiver.AlarmReceiver;

public class AlarmHelper {
	public static void setAlarm() {
		Intent alarmIntent = new Intent(AlarmApplication.applicationcontext,
				AlarmReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(
				AlarmApplication.applicationcontext, 0, alarmIntent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		AlarmManager alarmManager = (AlarmManager) AlarmApplication.applicationcontext
				.getSystemService(Context.ALARM_SERVICE);
		 long trigger = Calendar.getInstance().getTimeInMillis()+(PreferencesManager.getInstance().getAlarmHours()*3600000);
		alarmManager
				.set(AlarmManager.RTC_WAKEUP, trigger, pendingIntent);
	}
	public static void setSnooze(){
		Intent alarmIntent = new Intent(AlarmApplication.applicationcontext,
				AlarmReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(
				AlarmApplication.applicationcontext, 0, alarmIntent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		AlarmManager alarmManager = (AlarmManager) AlarmApplication.applicationcontext
				.getSystemService(Context.ALARM_SERVICE);
		alarmManager
				.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+(Config.SNOOZE_TIME_IN_MS), pendingIntent);
	}
	
	public static void deleteAlarms(){
		Intent alarmIntent = new Intent(AlarmApplication.applicationcontext,
				AlarmReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(
				AlarmApplication.applicationcontext, 0, alarmIntent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		AlarmManager alarmManager = (AlarmManager) AlarmApplication.applicationcontext
				.getSystemService(Context.ALARM_SERVICE);
		alarmManager.cancel(pendingIntent);
		pendingIntent.cancel();
		
	}
}
